#include<bits/stdc++.h>
using namespace std;
#define S_IT set<Node>::iterator	//S_IT = set_iterator
typedef char type;

struct Node {
	unsigned int l;
	unsigned int r;
	mutable type data;
	Node(unsigned int a, unsigned int b = 0, type c = 0);
	bool operator <(const Node &a) const {
		return l < a.l;
	}
};

Node::Node(unsigned int a, unsigned int b, type c) {
	l = a;
	r = b;
	data = c;
}

set<Node> s;

S_IT split(unsigned int pos) {
	S_IT it = s.lower_bound(Node(pos));
	if (it != s.end() && it->l == pos)
		return it;
	--it;
	unsigned int l = it->l, r = it->r;
	type data = it->data;
	s.erase(it);
	s.insert(Node(l, pos - 1, data));
	return s.insert(Node(pos, r, data)).first;
}

void assign(unsigned int l, unsigned int r, type val) {
	S_IT it2 = split(r + 1), it1 = split(l);
	s.erase(it1, it2);
	s.insert(Node(l, r, val));
	return;
}

int fun1(unsigned int l, unsigned int r, char k) {
	int cnt = 0;
	S_IT it2 = split(r + 1), it1 = split(l);
	for (; it1 != it2; ++it1) {
//		cout << " ??? " << it1->data << endl;
		if (it1->data == k) {
			cnt++;
//			cout << cnt << "  !!!!  " << it1->data << endl;
		}
	}
	return cnt;
}

void fun3(unsigned int l, unsigned int r) {
	S_IT it2 = split(r + 1), it1 = split(l);

	S_IT it = split(l);

	string tmp;
	for (; it1 != it2; ++it1) {
		tmp += it1->data;
	}

	sort(tmp.begin(), tmp.end());
	s.erase(it, it2);
	for (int i = 0; i < tmp.size(); i++)
		s.insert(Node(l + i, l + i, tmp[i]));
}

signed main() {
	int n, q;
	cin >> n >> q;
	string t;
	cin >> t;

	// 珂朵莉树初始化
	for (int i = 0; i < n; ++i) {
		type temp = t[i];
		s.insert(Node(i, i, temp));
	}

	while (q--) {
		int op;
		cin >> op;
		if (op == 1) {
			int x, y;
			char k;
			cin >> x >> y >> k;
			cout << fun1(x - 1, y - 1, k) << endl;
		} else if (op == 2) {
			int x, y;
			char k;
			cin >> x >> y >> k;
//			assign(x - 1, y - 1, k);
			S_IT it2 = split(y), it1 = split(x - 1);
			s.erase(it1, it2);
			for (int i = x - 1; i < y; ++i) {
				type temp = k;
				s.insert(Node(i, i, temp));
			}
		} else {
			int x, y;
			cin >> x >> y;
			fun3(x - 1, y - 1);
		}
	}
	return 0;
}
